#! /usr/bin/env python
# -*- coding: utf-8 -*-


from rest_framework import serializers
from models import PocUser
from models import PocUserRank
from models import Department
from models import Importance
from models import Progress
from models import Poc
from models import PocTrack
import time


class UserRankSerializer(serializers.ModelSerializer):
    class Meta:
        model = PocUserRank
        fields = '__all__'

class UserSerializer(serializers.ModelSerializer):
    insert_time = serializers.SerializerMethodField()
    user_rank = UserRankSerializer()
    class Meta:
        model = PocUser
        fields = '__all__'
    def get_insert_time(self, obj):
        return int(time.mktime(obj.insert_time.timetuple())) * 1000



class ImportanceSerializer(serializers.ModelSerializer):
    class Meta:
        model = Importance
        fields = '__all__'


class DepartmentSerializer(serializers.ModelSerializer):
    class Meta:
        model = Department
        fields = '__all__'


class ProgressSerializer(serializers.ModelSerializer):
    class Meta:
        model = Progress
        fields = '__all__'


class PocSerializer(serializers.ModelSerializer):
    poc_user=UserSerializer()
    importance = ImportanceSerializer()
    department = DepartmentSerializer()
    progress = ProgressSerializer()
    exchange_time = serializers.SerializerMethodField()
    class Meta:
        model = Poc
        fields = '__all__'

    def get_exchange_time(self, obj):
        return int(time.mktime(obj.exchange_time.timetuple())) * 1000


class TrackSerializer(serializers.ModelSerializer):
    poc = PocSerializer()
    track_time = serializers.SerializerMethodField()

    class Meta:
        model = PocTrack
        fields = '__all__'

    def get_track_time(self, obj):
        return int(time.mktime(obj.track_time.timetuple())) * 1000
